package com.finance.scheduler.job;

import com.finance.framework.qurtz.TaskDescriptor;
import com.finance.scheduler.service.AbstractTask;
import com.finance.scheduler.service.ManSalaryUploadManager;
import com.finance.util.DateUtil;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

/**
 * @Author: gly
 * @Date: Created in 2017/05/04
 */
@Component
@DisallowConcurrentExecution
public class ManSalaryDataUploadJob implements AbstractTask{
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ManSalaryUploadManager manSalaryUploadManager;


    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        this.logger.info("生成配费文件任务调度成功 任务开始执行 当前时间为：{}",DateUtil.dateFormat(new Date(),"yyyy/MM/dd hh:mm:ss"));
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.MONTH,-1);
        String month = DateUtil.dateFormat(calendar.getTime(),"yyyy-MM");
        manSalaryUploadManager.upload(month);
    }

    @Override
    public TaskDescriptor descriptor() {
        return new TaskDescriptor("配费文件上传","default","manSalaryUpload_trigger","manSalaryUpload_trigger","0 30 19 17 * ? ",this.getClass().getCanonicalName(),"拉取员工月结表 上传至OSS");
    }

}
